package com.seo.controller.index;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.seo.service.user.sdk.UserDomainService;
import com.seo.utils.Jurisdiction;

import lombok.extern.slf4j.Slf4j;

/**
 * 首页controller <br/>
 * 
 * @author shibeilei
 * @version 2017.11.30 12:20
 */
@Slf4j
@Controller
@RequestMapping(value = "/")
public class IndexController {

	@Autowired
	private UserDomainService userDomainService;

	@RequestMapping
	public String index(Integer parantId, HttpServletRequest request, HttpSession session) {
		log.info("进入首页...");

		return "index";

	}
	
	@RequestMapping("checkActive")
	@ResponseBody
	public String checkActive(Integer parantId, HttpServletRequest request, HttpSession session) {
		return "ok";
	}

	@RequestMapping("getRegisterDomain")
	public String getRegisterDomain(Integer parantId, HttpServletRequest request, HttpSession session) {
		log.info("获取注册地址...");
		String seoDomain = userDomainService.getSeoDomain();
		String inviteCode = Jurisdiction.getT("inviteCode", String.class);
		if (StringUtils.isEmpty(inviteCode)) {
			request.setAttribute("value", seoDomain + "/register");
		} else {
			request.setAttribute("value", seoDomain + "/register?sInviteCode=" + inviteCode);
		}

		return "config/index";

	}
}
